//package com.mxm;
//
//import static org.junit.Assert.*;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import org.apache.ibatis.session.SqlSession;
//import org.apache.log4j.Logger;
//import org.junit.Test;
//
//import com.mxm.concroler.MyBatisUtil;
//import com.mxm.dao.BillMapper;
//import com.mxm.pojo.Bill;
//
//public class Try {
//
//	private Logger logger = Logger.getLogger(Try.class);
//
//	@Test
//	public void test() {
//		SqlSession sqlSession = null;
//		List<Bill> list = new ArrayList<Bill>();
//		try {
//			sqlSession = MyBatisUtil.getSqlsession();
//			list = sqlSession.getMapper(BillMapper.class).getAllBill();
//		} catch (Exception e) {
//		}
//		for (Bill bill : list) {
//			System.out.println(bill.getProductName());
//		}
//	}
// }
package com.mxm;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;
import org.junit.Test;

import com.mxm.concroler.MyBatisUtil;
import com.mxm.dao.BillMapper;
import com.mxm.pojo.Bill;

public class Try {
	private Logger logger = Logger.getLogger(Try.class);

	@Test
	public void test() {
		SqlSession sqlSession = null;
		List<Bill> list = new ArrayList<Bill>();

		try {
			sqlSession = MyBatisUtil.getSqlsession();
			list = sqlSession.getMapper(BillMapper.class).getAllBill();

		} catch (Exception e) {
			e.printStackTrace();
		}
		for (Bill bill : list) {
			System.out.println("》》》》》》》》》" + bill.getProductName());
		}

	}

	@Test
	public void findByidTest() {
		// 根据id查询
		Integer id = 1;
		SqlSession sqlSession = MyBatisUtil.getSqlsession();
		Bill bill = sqlSession.getMapper(BillMapper.class).getByidBill(8);
		System.out.println(">>>id=" + bill.getId() + ">>>"
				+ bill.getProductName());

	}

	// @Test
	// public void findTreyTest() {
	// // 根据数量及单位查询
	// SqlSession sqlSession = MyBatisUtil.getSqlsession();
	// List<Bill> list = sqlSession.getMapper(BillMapper.class).getByBill("个",
	// 600);
	// System.out.println(list.size());
	// for (Bill bill : list) {
	// System.out.println("》》》》》》》》》" + bill.getProductName());
	// }
	// }

	// @Test
	// public void findTreyTest1() {
	// //降属性封装在map
	// Map<String, Object> map = new HashMap<String, Object>();
	// map.put("productUnit", "个");
	// map.put("productCount", 600);
	// SqlSession sqlSession = MyBatisUtil.getSqlsession();
	// List<Bill> list = sqlSession.getMapper(BillMapper.class).getByBill(map);
	// System.out.println(list.size());
	// for (Bill bill : list) {
	// System.out.println("》》》》》》》》》" + bill.getProductName());
	// }
	// }

	@Test
	public void findTest1() {
		Bill bill = new Bill();
		bill.setProductCount(600.00);
		bill.setProductUnit("个");
		SqlSession sqlSession = MyBatisUtil.getSqlsession();
		List<Bill> list = sqlSession.getMapper(BillMapper.class)
				.getByBill(bill);
		for (Bill bill1 : list) {
			System.out.println("》》》》》》》》》" + bill1.getProductName());
		}
	}

	@Test
	public void addBill() {
		Bill bill = new Bill();
		bill.setBillCode("BILL2016_020");
		bill.setProductName("手機");
		bill.setProductDesc("日常 數碼用品");
		bill.setProductCount(3000.00);
		bill.setTotalPrice(9000.00);
		bill.setIsPayment(1);
		bill.setProductUnit("個");
		bill.setCreatedBy(1);
		bill.setProviderId(4);
		SqlSession sqlSession = MyBatisUtil.getSqlsession();
		int i = sqlSession.getMapper(BillMapper.class).addBill(bill);
		System.out.println(">>>>>i=" + i);
		sqlSession.commit();
	}

	@Test
	public void updateBill() {
		Bill bill = new Bill();
		bill.setId(19);
		bill.setBillCode("123456");
		bill.setProductName("外星人");
		SqlSession sqlSession = MyBatisUtil.getSqlsession();
		int i = sqlSession.getMapper(BillMapper.class).updateBill(bill);
		System.out.println(">>>>>i=" + i);
		sqlSession.commit();
	}

	@Test
	public void deleteTest() {
		int id = 19;
		SqlSession sqlSession = MyBatisUtil.getSqlsession();
		int i = sqlSession.getMapper(BillMapper.class).deleteBill(id);
		System.out.println(">>>>>i=" + i);
		sqlSession.commit();
	}

}